package org.csu.mypetstore.web.servlets;

import org.csu.mypetstore.domain.Account;
import org.csu.mypetstore.service.LogService;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "EditAccountServlet", value = "/EditAccountServlet")
public class EditAccountServlet extends HttpServlet {

    private static final String EDITACOUNT = "/WEB-INF/jsp/account/EditAccountForm.jsp";
    private LogService logService = new LogService();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        HttpSession session = request.getSession();
        Account accountTemp = (Account)session.getAttribute("account");

        if(accountTemp != null){
            String logInfo = logService.logInfo(" ")  + " 跳转到编辑账号信息界面";
            logService.insertLogInfo(accountTemp.getUsername(), logInfo);
        }
        request.getRequestDispatcher(EDITACOUNT).forward(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }
}
